      SUBROUTINE EXTRAH_MPI &
      & (var, ix0, ix1, iy0, iy1, is0, is1, &
      & i0, i1, j0, j1, k0, k1)

!
! extrapolates values of a variable to its outside horizontal border
!

      use MPI_VARIABLES, only : &
      & xlbound, xrbound, ylbound, yrbound, &
      & nx0i, nx1e, nx2e, ny0i, ny1e, ny2e, &
      & nxs2i, nxs2e, nys2i, nys2e

      implicit none

      ! Input/output variables
      integer(4), intent(in) :: ix0, ix1, iy0, iy1, is0, is1
      integer(4), intent(in) :: i0, i1, j0, j1, k0, k1

      real(8), intent(inout) :: var(ix0:ix1,iy0:iy1,is0:is1)
      
      ! Local variables
      integer(4) :: ix, iy, k ! Loop indices

      if (ylbound) then
        do k = k0, k1
          do ix = max(i0+1,nx0i), min(i1-1,nx2e)
            var(ix,j0,k) = var(ix,j0+1,k)
          enddo
        enddo
      endif

      if (yrbound) then
        do k = k0, k1
          do ix = max(i0+1,nx0i), min(i1-1,nx2e)
            var(ix,j1,k) = var(ix,j1-1,k)
          enddo
        enddo 
      endif

      if (xlbound) then
        do k = k0, k1
          do iy = max(j0,ny0i), min(j1,ny2e)
            var(i0,iy,k) = var(i0+1,iy,k)
          enddo
        enddo
      endif

      if (xrbound) then
        do k = k0, k1
          do iy = max(j0,ny0i), min(j1,ny2e)
            var(i1,iy,k) = var(i1-1,iy,k)
          enddo
        enddo      
      endif

      return
      END SUBROUTINE EXTRAH_MPI
